//
//  KDBaseBoardModel.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/6/5.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "KDBaseBoardModel.h"
#import <sqlite3.h>
@implementation KDBaseBoardModel
- (void)encodeWithCoder:(NSCoder *)encoder
{
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([KDBaseBoardModel class], &count);
    for (int i = 0; i < count; i ++) {
        Ivar ivar = ivars[i];
        //取出i位置de成员变量
        const char *name = ivar_getName(ivar);
        
        //
        NSString *key = [NSString stringWithUTF8String:name];
        id value = [self valueForKey:key];
        [encoder encodeObject:value forKey:key];
    }
    free(ivars);
    
}
- (instancetype)initWithCoder:(NSCoder *)decoder
{
    if (self = [super init]) {
        unsigned int count = 0;
        Ivar *ivars = class_copyIvarList([KDBaseBoardModel class], &count);
        for (int i = 0; i < count; i ++) {
            Ivar ivar = ivars[i];
            //取出i位置de成员变量
            const char *name = ivar_getName(ivar);
            
            //
            NSString *key = [NSString stringWithUTF8String:name];                id value = [decoder decodeObjectForKey:key];
            if (value) {
                [self setValue:value forKey:key];
            }
        }
        free(ivars);
    }
    return self;
}
- (NSString *)description
{
    return [NSString stringWithFormat:@"\nwebSrcType<->%@\nstartTime<->%@\nendTime<-> %@\ndocType<-> %@\nbusinessSubType<-> %@\ntimeIndex<-> %@", self.webSrcType, self.startTime,self.endTime,self.docType,self.subtype,self.timeIndex];
}
//-(NSInteger)regionType{
//    return _regionType;
//}
- (void)setWebSrcType:(NSString *)webSrcType
{
    //如果被选中的不是国内或媒体按钮，那信息类型选项就默认为0
    _webSrcType = webSrcType;
    if ([webSrcType isEqualToString:@"0"] ||[webSrcType isEqualToString:@"2"] || [webSrcType isEqualToString:@"4"]) {
        _subtype = @"0";
    }
}
@end
